package com.thoughtworks.stafftimetable.domain;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;


public class Consultant {
    private String name;
    private List<Assignment> assignments = new ArrayList<Assignment>();

    public Consultant(String name) {
        this.name = name;
    }

    public String getName() {
        return name;
    }

    public void addAssignment(Assignment assignment) {
        this.assignments.add(assignment);
    }

    public List<Assignment> getAssignments() {
        return assignments;
    }

    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Consultant that = (Consultant) o;

        if (name != null ? !name.equals(that.name) : that.name != null) return false;

        return true;
    }

    public int hashCode() {
        return (name != null ? name.hashCode() : 0);
    }

    public String getAssignmentForSpecifiedDay(Date day) {
        for (Assignment assignment : assignments) {
            if (assignment instanceof ScheduledAssignment) {
                ScheduledAssignment scheduledAssignment = (ScheduledAssignment) assignment;
                if (day.equals(scheduledAssignment.getStartDate()) || day.equals(scheduledAssignment.getEndDate())) {
                    return assignment.getDescription();
                }
                if (day.after(scheduledAssignment.getStartDate()) && day.before(scheduledAssignment.getEndDate())) {
                    return assignment.getDescription();
                }
            }
        }
        return "ThoughtWorks - Beach";
    }
}
